<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
<script>
  // 隐藏数据
  // 实现一个简单的cache工具
  // 闭包隐藏数据，只提供 API
  // TODO: 实现私有变量: -> https://segmentfault.com/a/1190000017081250 
  function createCache() {
      const data = {}; // 闭包中的数据, 被隐藏, 不被外界访问
      return {
        set(key, val) {
          data[key] = val;
        },
        get(key) {
          return data[key];
        }
      }
  }

  const c = createCache();
  c.set('a', 100);
  console.log( c.get('a') );

</script>
</body>
</html>